﻿


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using EasyNet.Solr;
using EasyNet.Solr.Commons;
using System.Collections;
using System.Reflection;

namespace SolrExample.Tests.EasyNetSolr
{
#region solr update 
	public partial class SolrExample
	{
					//private string id;
			
			public string id {get; set;}
					//private string name;
			
			public string name {get; set;}
					//private float weight;
			
			public float weight {get; set;}
					//private bool inStock;
			
			public bool inStock {get; set;}
					//private IList<string> title;
			
			public IList<string> title {get; set;}
					//private string author;
			
			public string author {get; set;}
					//private string description;
			
			public string description {get; set;}
					//private string keywords;
			
			public string keywords {get; set;}
					//private string content;
			
			public string content {get; set;}
					//private DateTime? last_modified;
			
			public DateTime? last_modified {get; set;}
					//private double d_d;
			
			public double d_d {get; set;}
			}
	
	public class SolrExampleSerializer : IObjectSerializer<SolrExample>
    {
        public IEnumerable<SolrInputDocument> Serialize(IEnumerable<SolrExample> objs)
        {
            if (objs == null)
            {
                yield return null;
            }

            foreach (var obj in objs)
            {
                var doc = new SolrInputDocument();
				                doc.Add("id", new SolrInputField("id", obj.id));
				                doc.Add("name", new SolrInputField("name", obj.name));
				                doc.Add("weight", new SolrInputField("weight", obj.weight));
				                doc.Add("inStock", new SolrInputField("inStock", obj.inStock));
				                doc.Add("title", new SolrInputField("title", obj.title));
				                doc.Add("author", new SolrInputField("author", obj.author));
				                doc.Add("description", new SolrInputField("description", obj.description));
				                doc.Add("keywords", new SolrInputField("keywords", obj.keywords));
				                doc.Add("content", new SolrInputField("content", obj.content));
				                doc.Add("last_modified", new SolrInputField("last_modified", obj.last_modified));
				                doc.Add("d_d", new SolrInputField("d_d", obj.d_d));
				                yield return doc;
            }
        }
        
    }
    
    
    #endregion
    
    #region solr query 
	public partial class SolrExampleResult
	{
					//private string id;			
			public string id {get; set;}
					//private string name;			
			public string name {get; set;}
					//private float weight;			
			public float weight {get; set;}
					//private bool inStock;			
			public bool inStock {get; set;}
					//private IList<string> title;			
			public IList<string> title {get; set;}
					//private DateTime? last_modified;			
			public DateTime? last_modified {get; set;}
			}
	
    public class SolrExampleDeSerializer : IObjectDeserializer<SolrExampleResult>
    {
		public IEnumerable<SolrExampleResult> Deserialize(SolrDocumentList result)
        {
            if (result == null)
            {
                yield return null;
            }
						
            foreach (SolrDocument doc in result)
            {
                var record = new SolrExampleResult();
                                if (doc.ContainsKey("id"))
                {
					record.id = doc["id"].ToString();
                }
                                if (doc.ContainsKey("name"))
                {
					record.name = doc["name"].ToString();
                }
                                if (doc.ContainsKey("weight"))
                {
					record.weight = float.Parse(doc["weight"].ToString());
                }
                                if (doc.ContainsKey("inStock"))
                {
					record.inStock = Convert.ToBoolean(doc["inStock"].ToString());
                }
                                if (doc.ContainsKey("title"))
                {
					var array = (System.Collections.ArrayList)doc["title"];if (array != null){	foreach (object catOB in array){		if (catOB != null){			if (record.title == null)			{				record.title = new List<string>();			}			record.title.Add(catOB.ToString());}}};
                }
                                if (doc.ContainsKey("last_modified"))
                {
					if(doc["last_modified"]==null){record.last_modified = DateTime.MinValue;}else{record.last_modified = DateTime.Parse(doc["last_modified"].ToString());};
                }
                                
                yield return record;
            }
        }
        
	}
	
    #endregion
}

